<script setup lang="ts">
import { propTypes } from '@/utils/propTypes'

const props = defineProps({
  src: propTypes.string.def(''),
  width: {
    type: [Number, String],
    default: '',
  },
  height: {
    type: [Number, String],
    default: '',
  },
})

const realSrc = computed(() => {
  if (!props.src)
    return

  const real_src = props.src.split(',')[0]
  return real_src
})

const realSrcList = computed(() => {
  if (!props.src)
    return

  const real_src_list = props.src.split(',')
  const srcList: string[] = []
  real_src_list.forEach((item) => {
    return srcList.push(item)
  })
  return srcList
})

const visible = ref(false)

const realWidth = computed(() =>
  typeof props.width == 'string' ? props.width : `${props.width}px`,
)

const realHeight = computed(() =>
  typeof props.height == 'string' ? props.height : `${props.height}px`,
)
</script>

<template>
  <a-image
    :preview="{ visible: false }"
    fallback=""
    :src="`${realSrc}`" fit="cover" :width="realWidth" :height="realHeight"
    @click="visible = true"
  />
  <div style="display: none">
    <a-image-preview-group :preview="{ visible, onVisibleChange: (vis:boolean) => (visible = vis) }">
      <a-image
        v-for="(item, index) in realSrcList" :key="index"
        :src="item"
      />
    </a-image-preview-group>
  </div>
</template>

<style lang="less" scoped>
</style>
